import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import axios from 'axios'
import api from '../assets/config/api'
export default new Vuex.Store({
  state: {
    cartList: [],
    cartTotal: {
      goodsCount: 0,
      checkedGoodsAmount: 0,
      checkedGoodsCount: 0,
      goodsAmount: 0,
    },
  },
  mutations: {
    SETCARTLIST(state, cartList) {
      state.cartList = cartList
    },
    SETCARTTOTAL(state, cartTotal) {
      state.cartTotal = cartTotal
    },
  },
  actions: {
    async setCart(content) {
      let cartRes = await axios.get(api.CartList)
      content.commit('SETCARTLIST', cartRes.data.data.cartList)
      content.commit('SETCARTTOTAL', cartRes.data.data.cartTotal)
    },
  },
  modules: {},
})
